
import * as api from '@/service/auth'
import { setToken } from '@/utils/auth'
const Model = {
  namespace: 'auth',
  state: {
    info: {}
  },
  effects: {
    *login({payload}, {call, put}) {
      const res = yield call(api.login, payload)
      return new Promise((resolve, reject) => {
        if(res) {
          setToken(res.data.token)
          resolve(res)
        } else {
          reject()
        }
      })
    },
    *changePwd({payload}, {call, put}) {
      const res = yield call(api.changePwd, payload)
      return new Promise((resolve, reject) => {
        if(res) {
          setToken(res.data.token)
          resolve(res)
        } else {
          reject()
        }
      })
    },
  },
  reducers: {
    save(state, action) {
      return{state, [action.payload.key]: action.payload.data}
    }
  }
}
export default Model